package com.example.makerspace.controller.maker;

import com.example.makerspace.dto.Result;
import com.example.makerspace.dto.maker.TaskBaseDTO;
import com.example.makerspace.dto.maker.TaskQueryDTO;
import com.example.makerspace.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@ResponseBody
@RequestMapping("/api/task")
public class TaskController {

    @Autowired
    private TaskService taskService;

    @GetMapping("/queryCatalog")
    public Result queryCatalog() {
        return taskService.queryCatalog();
    }

    @GetMapping("/queryInStatus")
    public Result queryInStatus() {
        return taskService.queryInStatus();
    }

    @PostMapping("/create")
    public Result create(@RequestBody TaskBaseDTO taskBaseDTO, HttpServletRequest request) {
        return taskService.create(taskBaseDTO, request);
    }

    @PostMapping("/update")
    public Result update(@RequestBody TaskBaseDTO taskBaseDTO) {
        return taskService.update(taskBaseDTO);
    }

    @PostMapping("/query")
    public Result query(@RequestBody TaskQueryDTO taskQueryDTO) {
        return taskService.query(taskQueryDTO);
    }

    @GetMapping("/queryById")
    public Result queryById(@RequestParam("id") Integer id,HttpServletRequest request) {
        return taskService.queryById(id,request);
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody TaskBaseDTO taskBaseDTO) {
        return taskService.delete(taskBaseDTO.getId());
    }

    @PostMapping("/updatePublishStatus")
    public Result updatePublishStatus(@RequestBody TaskBaseDTO taskBaseDTO) {
        return taskService.updatePublishStatus(taskBaseDTO);
    }

    @PostMapping("/addView")
    public Result addView(@RequestBody TaskBaseDTO taskBaseDTO) {
        return taskService.addView(taskBaseDTO.getId());
    }

    @PostMapping("/follow")
    public Result follow(@RequestBody TaskBaseDTO taskBaseDTO, HttpServletRequest request) {
        return taskService.follow(taskBaseDTO.getId(),request);
    }

    @PostMapping("/cancelFollow")
    public Result cancelFollow(@RequestBody TaskBaseDTO taskBaseDTO, HttpServletRequest request) {
        return taskService.cancelFollow(taskBaseDTO.getId(),request);
    }

}
